let Toast = require('../utils/compile/toast').default

function createToastManager() {
  let toastLock = false

  let ret = {
    methods: {
      showDevToast(message, title = '', options) {
        if (!toastLock) {
          toastLock = true
          wx.showModal({
            title: title,
            content: `${message}`,
            showCancel: false,
            ...options,
            complete: function () {
              toastLock = false
            }
          })
        }
      },
      setToastLock(b) {
        toastLock = b
      },
      showToast(title, duration = 3000, cb) {
        // if (!toastLock) {
        //   toastLock = true
        //   console.log('showToast', title)
        //   wx.showToast({
        //     title: title,
        //     icon: 'none',
        //     duration: duration,
        //     complete: function () {
        //       toastLock = false
        //       cb && cb()
        //     }
        //   })
        // }
        if (!toastLock) {
          toastLock = true
          console.log('showToast', title)
          Toast({
            message: title,
            duration: duration,
            onClose: function () {
              console.log('on toast close')
              toastLock = false
              cb && cb()
            }
          })
        }
      },
    }
  }

  return ret
}

module.exports = {
  createToastManager
}
